#!/bin/bash

function usage 
{
	echo -e "Wrong number of parameters!"
	echo -e "Usage:"
	echo -e "	remove_module <module name> <package>"
	echo -e "	- <module name>: Name of an existent module."
	echo -e "	- <source package>: The module's package."
	echo -e ""
	echo -e "	Example:"
	echo -e "		remove_module my_module my.module.package"

	exit 1
}

if [ $# -lt 2 ]
then
	usage
fi

path=`echo -e "${2}" | sed "s!\.!/!g"`

if [ -e "${path}/${1}.py" ]
then
	rm "${path}/${1}.py"
fi

if [ -e "${path}/__init__.py" ]
then
	line=`grep -n -m 1 -w "from ${1} import *" "${path}/__init__.py" | cut -f1 -d:`

	if [ -n "${line}" ]
	then
		sed -i "${line}d" "${path}/__init__.py"
	fi
fi
